home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / HippoDraw / HippoDrawSrc1.1 / Hippo.subproj / Overlay.m < prev    next >
Encoding:
Text File  |  1992-04-25  |  5.2 KB  |  230 lines

  1. /* Overlay.m    by Paul Kunz    March 1991
  2.  * Group of Plot graphics that overlay each other.
  3.  *
  4.  * Copyright (C)  1992  The Board of Trustees of
  5.  * The Leland Stanford Junior University.  All Rights Reserved.
  6.  */
  7.  
  8. #import "Overlay.h"
  9.  
  10. const char Overlay_h_rcsid[] = OVERLAY_H_ID;
  11. const char Overlay_m_rcsid[] = "$Id: Overlay.m,v 1.5 1992/04/22 00:44:20 pfkeb Rel $";
  12.  
  13. #import <appkit/nextstd.h>
  14. #import <objc/List.h>
  15.  
  16. #import "DrawDocument.h"
  17. #import "HGraphicView.h"
  18. #import "Plot.h"
  19.  
  20. @implementation Overlay
  21.  
  22. - initList:list with:plot
  23. {
  24.     id            g;
  25.     unsigned int    i;
  26.     int            flag = 0;
  27.     int         logX, logY;
  28.     
  29.     [super initList:list];
  30.     
  31.     [self getExtendedBounds:&initialRect];
  32.     firstPlot = plot;
  33.     [self checkBounds];
  34.     logX = [firstPlot isLogScaleX];
  35.     logY = [firstPlot isLogScaleY];
  36.     [firstPlot setAutoScaleX:&flag];
  37.     [firstPlot setAutoScaleY:&flag];
  38.     lastRect = bounds;
  39.     i = [components count];
  40.     while ( i-- ) {
  41.         g = [components objectAt:i];
  42.     if ( g != firstPlot ) {
  43.         [g setRangesFrom:firstPlot];
  44.         [g setTitlesFlag:&flag];
  45.         [g setAxesFlag:&flag];
  46.         [g setLogScaleX:&logX];
  47.         [g setLogScaleY:&logY];
  48.         [g setBounds:&bounds];
  49.     }
  50.     }
  51.     
  52.     return self;
  53. }
  54. - checkBounds
  55. {
  56.     NXRect    frameRect;
  57.     NXCoord    edge;
  58.     
  59.     [firstPlot getBounds:&bounds];
  60.     [[[[firstPlot graphicView] window] delegate] getPageFrame:&frameRect];
  61.     if ( NXContainsRect( &frameRect, &bounds) ) {
  62.         return self;
  63.     }
  64.     edge = NX_MAXX(&frameRect);
  65.     if ( NX_MAXX(&bounds) > edge ) {
  66.         [firstPlot moveRightEdgeTo:&edge];
  67.     }
  68.     edge = NX_MAXY(&frameRect);
  69.     if ( NX_MAXY(&bounds) > edge ) {
  70.         [firstPlot moveTopEdgeTo:&edge ];
  71.     }
  72.     edge = NX_X(&frameRect);
  73.     if ( NX_X(&bounds) < edge ) {
  74.     [firstPlot moveLeftEdgeTo:&edge];
  75.     }
  76.     edge = NX_Y(&frameRect);
  77.     if ( NX_Y(&bounds) < edge ) {
  78.         [firstPlot moveBottomEdgeTo:&edge ];
  79.     }
  80.     [firstPlot getBounds:&bounds];
  81.     NXUnionRect(&bounds, &initialRect);
  82.     return self;
  83. }
  84. - (NXRect *) getInitialBounds:(NXRect *)initBounds
  85. {
  86.     *initBounds = initialRect;
  87.     return initBounds;
  88. }
  89. - transferSubGraphicsTo:list at:(int)position
  90. {
  91.     id        g;
  92.     NXRect    b;
  93.     int        i, flag = 1;
  94.  
  95.     b = bounds;
  96.     i = [components count];
  97.     while ( i-- ) {
  98.     g = [components objectAt:i];
  99.         if ( [g isKindOf:[Plot class]] ) {
  100.         [g setTitlesFlag:&flag];
  101.         [g setAxesFlag:&flag];
  102.         [g setBounds:&b];
  103.         b.origin.x += 10.0;
  104.         b.origin.y -= 10.0;
  105.     }
  106.     }
  107.     [super transferSubGraphicsTo:list at:position];
  108.     return self;
  109. }
  110.  
  111. - firstPlot
  112. {
  113.     return firstPlot;
  114. }
  115. - NameAxisX:(const char *) stringValue
  116. {
  117.     [firstPlot NameAxisX:stringValue];
  118.     return self;
  119. }
  120. - NameAxisY:(const char *) stringValue
  121. {
  122.     [firstPlot NameAxisY:stringValue];
  123.     return self;
  124. }
  125. - setAutoScaleX:(const int *) value
  126. {
  127.     id            plot;
  128.     NXPoint        range, max_range;
  129.     unsigned int    i, count;
  130.     int            state;
  131.     
  132.     state = *value;
  133.     if ( state ) {
  134.         [self makeGraphicsPerform:@selector(setAutoScaleX:) with:&state];
  135.     state = 0;
  136.     max_range.x = +1.0;
  137.     max_range.y = -1.0;
  138.     count = [components count];
  139.     for ( i = 0; i < count; i++ ) {
  140.         plot = [components objectAt:i];
  141.         if ( [plot isKindOf:[Plot class]] ) {
  142.         [plot getRangeForAxisX: &range];
  143.         max_range.x = MIN( max_range.x, range.x);
  144.         max_range.y = MAX( max_range.y, range.y);
  145.         [plot setAutoScaleX:&state];
  146.         }
  147.     }
  148.         [self makeGraphicsPerform:@selector(setRangeForAxisX:)
  149.                  with:&max_range];
  150.     }
  151.     return self;
  152. }
  153. - setAutoScaleY:(const int *) value
  154. {
  155.     id            plot, save_plot;
  156.     NXPoint        range, max_range;
  157.     graphtype_t        plot_t;
  158.     unsigned int    i, count;
  159.     int            state;
  160.     
  161.     state = *value;
  162.     if ( state ) {
  163.         [self makeGraphicsPerform:@selector(setAutoScaleY:) with:&state];
  164.     state = 0;
  165.     save_plot = nil;
  166.     [firstPlot getRangeForAxisY:&max_range];
  167.     [firstPlot setAutoScaleY:&state];
  168.     count = [components count];
  169.     for ( i = 0; i < count; i++ ) {
  170.         plot = [components objectAt:i];
  171.         if ( (plot != firstPlot) && [plot isKindOf:[Plot class]] ) {
  172.         [plot getRangeForAxisY: &range normalizedTo:firstPlot];
  173.         max_range.x = MIN( max_range.x, range.x);
  174.         max_range.y = MAX( max_range.y, range.y);
  175.         [plot setAutoScaleY:&state];
  176.         }
  177.     }
  178.     [firstPlot setRangeForAxisY:&max_range];
  179.     [firstPlot getDispType:&plot_t];
  180.     if ( plot_t == HISTOGRAM ) {
  181.         for ( i = 0; i < count; i++ ) {
  182.         plot = [components objectAt:i];
  183.         if ( plot != firstPlot ) {
  184.             [plot setRangesFrom:firstPlot];
  185.         }
  186.         }
  187.     } else {
  188.             [self makeGraphicsPerform:@selector(setRangeForAxisY:)
  189.                      with:&max_range];
  190.     }
  191.     }
  192.     return self;
  193. }
  194. - setRangeForAxisY:(NXPoint *) value
  195. {
  196.     unsigned int    i;
  197.     
  198.     [firstPlot setRangeForAxisY:value];
  199.     i = [components count];
  200.     while ( i-- ) {
  201.         [[components objectAt:i] setRangesFrom:firstPlot];
  202.     }
  203.     return self;
  204. }
  205. - setTitle:(const char *) stringValue
  206. {
  207.     [firstPlot setTitle:stringValue];
  208.     return self;
  209. }
  210. - setTitlesFlag:(const int *) value
  211. {
  212.     [firstPlot setTitlesFlag:value];
  213.     return self;
  214. }
  215.  
  216. /* Methods supporting archiving and de-archiving */
  217. - write:(NXTypedStream *) ts
  218. {
  219.     [super write:ts];
  220.     NXWriteObjectReference( ts, firstPlot );
  221.     return self;
  222. }
  223. - read:(NXTypedStream *)ts
  224. {
  225.     [super read:ts];
  226.     firstPlot = NXReadObject( ts );
  227.     return self;
  228. }
  229. @end
  230.